package it.kion.util.ui.ulog2.preferences;

import it.kion.util.ui.ulog2.Log4jPlugin;
import it.kion.util.ui.ulog2.Log4jUtil;

import org.eclipse.jface.preference.ColorFieldEditor;
import org.eclipse.jface.preference.FieldEditorPreferencePage;
import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.IWorkbenchPreferencePage;

public class ColorsPreferencePage extends FieldEditorPreferencePage implements
		IWorkbenchPreferencePage {

	public ColorsPreferencePage() {
		super(GRID);
		setPreferenceStore(Log4jPlugin.getDefault().getPreferenceStore());
		setDescription("Impostazioni dei colori di ULog2:");
		initializeDefaults();
	}

	public void createFieldEditors() {
		addField(new ColorFieldEditor(Log4jPlugin.DEBUG_COLOR_KEY, "Debug", getFieldEditorParent()));
		addField(new ColorFieldEditor(Log4jPlugin.INFO_COLOR_KEY, "Info", getFieldEditorParent()));
		addField(new ColorFieldEditor(Log4jPlugin.WARN_COLOR_KEY, "Warn", getFieldEditorParent()));
		addField(new ColorFieldEditor(Log4jPlugin.ERROR_COLOR_KEY, "Error", getFieldEditorParent()));
		addField(new ColorFieldEditor(Log4jPlugin.FATAL_COLOR_KEY, "Fatal", getFieldEditorParent()));

		addField(new ColorFieldEditor(Log4jPlugin.DEBUG_COLOR_KEY_BG, "Debug (BackGround)", getFieldEditorParent()));
		addField(new ColorFieldEditor(Log4jPlugin.INFO_COLOR_KEY_BG, "Info (BackGround)", getFieldEditorParent()));
		addField(new ColorFieldEditor(Log4jPlugin.WARN_COLOR_KEY_BG, "Warn (BackGround)", getFieldEditorParent()));
		addField(new ColorFieldEditor(Log4jPlugin.ERROR_COLOR_KEY_BG, "Error (BackGround)", getFieldEditorParent()));
		addField(new ColorFieldEditor(Log4jPlugin.FATAL_COLOR_KEY_BG, "Fatal (BackGround)", getFieldEditorParent()));
	}
	
	private void initializeDefaults() {
		Log4jUtil.initColorDefaults();
	}

	public void init(IWorkbench workbench) {
	}
	
	public boolean performOk() {
		boolean ok = super.performOk();
		Log4jUtil.updateColors();
		return ok;
	}

	protected void performApply() {
		super.performApply();
		Log4jUtil.updateColors();
	}
	
}